//
//  OneFloorVC.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/3/24.
//  Copyright © 2017年 金橙云. All rights reserved.
//

#import "OneFloorVC.h"

#import "TodoHttpManager.h"
#import "CustomCollectionViewCell.h"
@interface OneFloorVC ()<UICollectionViewDelegate,UICollectionViewDataSource>

{
    NSMutableArray *_oneArr;
    
    
}

@property(nonatomic,strong)UICollectionView *collectView;
@end

@implementation OneFloorVC

-(void)viewWillAppear:(BOOL)animated
{
    //房源(配套/商业)
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didTDZhuSHouse:) name:TDZhuSHouse object:nil];
    //TODO:房源(配套/商业)
    [_manager userZhuShouFangYuanWithType:@"1" withQi:@"2" withQuYU:nil withLou:@"9号楼"];
    
    
}

//房源(配套/商业)
-(void)didTDZhuSHouse:(NSNotification *)noti
{
    if (noti.object != 0)
    {
        int status = [[noti.object objectForKey:@"status"] intValue];
        if (status == 1)
        {
            _oneArr = [noti.object objectForKey:@"data"];
            
            NSLog(@"666666=======%@ oneArr",_oneArr);
            [_collectView reloadData];
        }
        else
        {
            [_manager MakeMyselfAlert:@"获取失败" andIsNeedTitle:NO andShowTime:2.0];
        }
    }
    
}

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:TDZhuSHouse object:nil];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = BgColor;
    _manager = [TodoHttpManager sharedManager];
    
    _oneArr = [[NSMutableArray alloc] init];
    
    //布局对象
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.minimumInteritemSpacing = 5;
    flowLayout.minimumLineSpacing = 5;
    flowLayout.itemSize = CGSizeMake((B_WIDTH-30)/3,40);
    
    // 内容 与控件四周的距离
    flowLayout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    _collectView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, B_WIDTH, B_HEIGHT-110)collectionViewLayout:flowLayout];
    _collectView.backgroundColor = BgColor;
    _collectView.delegate = self;
    _collectView.dataSource = self;
    [self.view addSubview:_collectView];
    //TODO:注册cell
    [_collectView registerClass:[CustomCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
    
}

#pragma mark - UICollectionViewDelegate&&DateSoucre

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _oneArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    //单元格初始化
    CustomCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];

    cell.backgroundColor = [UIColor whiteColor];
    cell.titleLab.text = [[_oneArr objectAtIndex:indexPath.row] objectForKey:@"room_num"];
    cell.statusBtn.tag = indexPath.row;
    
    
    
    
    
    
    
    return cell;
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(nonnull NSIndexPath *)indexPath
{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
